﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Timers;
using TwinCAT.Ads;
using Project_V1;

namespace Project_V1
{
    public partial class FrmSysSetings : Form
    {
        //初始化画面
        public FrmSysSetings()
        {
            InitializeComponent();            
        }

        //初始化各个控件状态
        private void Form1_Load(object sender, EventArgs e)
        {
            AMSNETID_Box1.Text = Beckhoff_PLC.AmsNetID;
            Disconnect_Button.Enabled = false;
        }

        //Connect按钮按下事件
        private void Connect_Button_Click(object sender, EventArgs e)
        {
            Connect_Button.Enabled = false;
            Disconnect_Button.Enabled = true;

            try
            {
                Beckhoff_PLC.CreateHandle();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //disconnect按钮，初始化控件状态，释放句柄
        private void Disconnect_Button_Click(object sender, EventArgs e)
        {
            Disconnect_Button.Enabled = false;
            Connect_Button.Enabled = true;
            Beckhoff_PLC.TcDispose();
        }

        private void btnConfrim_Click(object sender, EventArgs e)
        {
            Beckhoff_PLC.AmsNetID = AMSNETID_Box1.Text.ToString();//获取框中的netid
        }
    }
}